package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Cms;

@Stateless(name = "Cms")
public class CmsEJBImpl implements ICmsLocal{

	@PersistenceContext(unitName = "PU_Cargaison")
	private EntityManager em;
	
	@Override
	public void addCms(Cms c) {
		em.persist(c);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Cms> getAllCms() {
		Query req=em.createQuery("select c from Cms c");
		return req.getResultList();
	}

	@Override
	public Cms getCms(Integer Id) {
		Cms de=em.find(Cms.class, Id);
		if(de==null)throw new RuntimeException("Cms introuvable");
		return de;
	}

	@Override
	public void updateCms(Cms c) {
		em.merge(c);
	}


	@Override
	public void deleteCms(Integer Id) {
		Cms c=getCms(Id);
		em.remove(c);
	}

}
